<?php
declare(strict_types=1);
namespace App\ZxAdmin\Content\Album;
use App\Controller;
use Field\SysAlbumConst;
use Field\SysAlbumColumns;
use Field\SysAlbumRow;
// hook controller_zxadmin_content_album_sys_album_use.php

/**
 * @title   相册
 * @auth    true
 * @login   true
 * @menu    false
 * @component   vlist/index.vue
 * @icon    el-icon-menu
 * @active  true
 * @affix   false
 * @rank    1
 */
class SysAlbum extends Controller
{
    // hook controller_zxadmin_content_album_sys_album_public_start.php

    // make public SysAlbum Zxadmin\Content\Album
    /*
    protected array $echo_field 	=	[];
    protected array $edit_field	    =	[];
    protected array $add_field      =	[];
    protected array $field_fields_kv	=	[];
    protected array $Columns	    =	[];
    */
    public const make=1;
    /**
     * @title   列表配置
     */
    public const Conf=[
        'pageSize'=>25,
        'remoteSort'=>1,
        'remoteFilter'=>1,
        'remoteSummary'=>0,
        'hidePagination'=>1,
        'hideRefresh'=>1,
        'hideSetting'=>1,
        'hideDo'=>1,
        'add'=>1,
        'start'=>0,
        'stop'=>0,
        'delete'=>1,
        'import'=>0,
        'export'=>0
    ];
    /**
     * @title   列操作
     */
    public const Tools=[];
   /**
    * @title   列配置
    */
    public const Columns=[];
    /**
     * @title   筛选
     */
    public const Filter=[];
    /**
     * @title   添加内容
     */
    public const AddForm=[];
    /**
     * @title   编辑内容
     */
    public const EditForm=[];

    // hook controller_zxadmin_content_album_sys_album_public_end.php


    /**
     * @title   下发列表数据
     * @rank    99
     */
    public function action_Index()
    {
        // hook controller_zxadmin_content_album_sys_album_index_start.php
        $page= $this->request->param('page', 0);
        $size = $this->request->param('limit', 0);
        $field = $this->request->param('field', '');
        $sort = $this->request->param('sort', '');
        $order=[];
        !empty($field) && $order[$field] = $sort=='asc'?-1:1;
        $cond = [];

        $data = $this->SysAlbum->GetList($cond,$order,$page,$size);

        $data['data']= arraylist_tree($data['data'],SysAlbumConst::AlbumID,SysAlbumConst::ParentAlbumID,'children',false);

        // hook controller_zxadmin_content_album_sys_album_index_end.php
        $this->response('0000', $data);
    }


    /**
     * @title   新增提交
     * @rank    99
     */
    public function action_Add_POST()
    {
        // hook controller_zxadmin_content_album_sys_album_add_start.php
        $data=[];
        $data['ParentAlbumID']=$this->request->param('AlbumID',0);
        $data['Name']=$this->request->param('Name',"");
        $r = $this->SysAlbum->insert($data);
        // hook controller_zxadmin_content_album_sys_album_add_end.php
        $this->response($r?'0000':'0001', ['data' =>$r]);
    }
    /**
     * @title   编辑提交
     * @rank    99
     */
    public function action_Edit_POST()
    {
        // hook controller_zxadmin_content_album_sys_album_edit_start.php
        $data=[];
        $AlbumID=$this->request->param('AlbumID',0);
        $this->CheckEmpty([$AlbumID], ['AlbumID'])  ;
        $data['Name']=$this->request->param('Name',"");
        $r = $this->SysAlbum->updateByPk($AlbumID,$data);
        // hook controller_zxadmin_content_album_sys_album_edit_end.php
        $this->response($r?'0000':'0001', ['data' =>$r]);
    }


    //need_delete_start
     /**
      * @title   删除数据
      */
    public function action_Index_Delete()
    {
        // hook controller_zxadmin_content_album_sys_album_delete_start.php
        $data = $this->request->param('data',[]);
        $this->CheckEmpty([$data], ['操作数据为空']);
        $r = $this->SysAlbum->deleteByIndex($data);
        $cond_arr=[];
        foreach($data as $row){
            $cond_arr['AlbumID'][]=$row['AlbumID'];
        }
        $this->SysAlbumAttach->update($cond_arr,['AlbumID'=>1]);
        // hook controller_zxadmin_content_album_sys_album_delete_end.php
        $this->response($r?'0000':'0001', ['data' =>$r]);
    }
    //need_delete_end
    
    
    
    
    // hook controller_zxadmin_content_album_sys_album_end.php
}
?>